package com.ruoyi.lab.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.model.LoginUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lab.domain.LabMaintenanceScrap;
import com.ruoyi.lab.service.ILabMaintenanceScrapService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备报废与维修Controller
 * 
 * @author mojar
 * @date 2024-10-11
 */
@RestController
@RequestMapping("/lab/scrap")
public class LabMaintenanceScrapController extends BaseController
{
    @Autowired
    private ILabMaintenanceScrapService labMaintenanceScrapService;

    /**
     * 查询设备报废与维修列表
     */
    @PreAuthorize("@ss.hasPermi('lab:scrap:list')")
    @GetMapping("/list")
    public TableDataInfo list(LabMaintenanceScrap labMaintenanceScrap)
    {
        startPage();
        List<LabMaintenanceScrap> list = labMaintenanceScrapService.queryList(labMaintenanceScrap);
        return getDataTable(list);
    }

    /**
     * 导出设备报废与维修列表
     */
    @PreAuthorize("@ss.hasPermi('lab:scrap:export')")
    @Log(title = "设备报废与维修", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LabMaintenanceScrap labMaintenanceScrap)
    {
        List<LabMaintenanceScrap> list = labMaintenanceScrapService.queryList(labMaintenanceScrap);
        ExcelUtil<LabMaintenanceScrap> util = new ExcelUtil<>(LabMaintenanceScrap.class);
        util.exportExcel(response, list, "设备报废与维修数据");
    }

    /**
     * 获取设备报废与维修详细信息
     */
    @PreAuthorize("@ss.hasPermi('lab:scrap:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(labMaintenanceScrapService.getById(id));
    }

    /**
     * 新增设备报废与维修
     */
    @PreAuthorize("@ss.hasPermi('lab:scrap:add')")
    @Log(title = "设备报废与维修", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LabMaintenanceScrap labMaintenanceScrap)
    {
        return toAjax(labMaintenanceScrapService.save(labMaintenanceScrap));
    }

    /**
     * 修改设备报废与维修
     */
    @PreAuthorize("@ss.hasPermi('lab:scrap:edit')")
    @Log(title = "设备报废与维修", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LabMaintenanceScrap labMaintenanceScrap)
    {
        return toAjax(labMaintenanceScrapService.updateById(labMaintenanceScrap));
    }

    /**
     * 删除设备报废与维修
     */
    @PreAuthorize("@ss.hasPermi('lab:scrap:remove')")
    @Log(title = "设备报废与维修", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<String> ids)
    {
        return toAjax(labMaintenanceScrapService.removeBatchByIds(ids));
    }
}
